#ifndef TERRAINMANAGER_H
#define TERRAINMANAGER_H

#include "Singleton.h"
#include "Terrain.h"
#include <Vector>

class TerrainManager : public Singleton<TerrainManager>
{
public:
	TerrainManager();
	virtual ~TerrainManager();

	void SetNumChunks(int a_val) { m_numChunks = a_val; }
	void SetCellSpacing(int a_val) { m_cellSpacing = a_val; }
	bool CreateTerrain(char* a_pFileName, int a_numChunks);
	bool CreateWater(char* a_pFileName, int a_numChunks);
	void CalculateNormals(int a_height, int a_width, int a_numVerts);
	void Pick();

	//////////////////////////////////////////////////////////////////////////
	// Add a terrain chunk to the terrain list
	//
	// Paramaters:
	// a_pTerrain, a pointer to the chunk of terrain to add
	//
	// Returns true if it added it to the list
	// Returns false if it was unable to add
	//
	//////////////////////////////////////////////////////////////////////////
	bool AddTerrain(Terrain* a_pTerrain); 

	//////////////////////////////////////////////////////////////////////////
	// Get the height of the terrain at the given x and z position
	//
	// Paramaters:
	// a_xPos, the x position to use
	// a_zPos, the z position to use
	//
	// Returns the height value of the terrain at that position
	//
	//////////////////////////////////////////////////////////////////////////
	float GetTerrainHeight(float a_xPos, float a_zPos);

	typedef std::vector<Terrain*> TerrainVec;
	TerrainVec* GetTerrainVec() { return &m_terrain; }

	void AddHeightMap(char* a_pFileName);

	int GetCellSpacing() { return m_numChunks; }

	void AddSingleHeightMap(char* a_pFileName);
	void StitchTerrain(int a_terrainWidth, int a_totalVerts, int a_numVerts, int a_height, int a_width);

	void SmoothTerrain(int a_height, int a_width, int a_numVerts);



private:
	int m_numChunks;
	int m_cellSpacing;

	TerrainVec m_terrain;

	typedef std::vector<char*> HeightMapVector;
	HeightMapVector m_heightMapFileNames;

	char* m_heightMapFile;

};

#endif //TERRAINMANAGER_H